
// pipe1.c: communication over a pipe

#include "kernel/types.h"
#include "user/user.h"

int
main()
{
  int fds[2];
  char buf[100];
  int n;
  int fpid;
  

  // create a pipe, with two FDs in fds[0], fds[1].
  pipe(fds);
  fpid=fork();
  if(fpid){
  	write(fds[1], "hello\n", 6);
  	sleep(5);
  	close(fds[1]);
  	printf("write-end of pipe has been closed\n");
  	exit(0);
  }
  else{
  	n = read(fds[0], buf, sizeof(buf));
  
  	printf("Received:%d\n",n);
  	printf("CONTENT:\n******\n");
  	write(1, buf, n);  
  	printf("\n******\n");
  	
    	wait(0);
  	
  	n=read(fds[0],buf,sizeof(buf));
  	printf("Received:%d\n",n);
  	exit(0);

  }
  
  
  
  
  exit(0);
}
